window.rule_required =  
    rules:
        required: true
    messages:
        required: "不能为空"
    validate_cssclass: "required" 
    
window.rule_digits =
    rules:
        digits: true
    messages:
        digits: "必须为数字"
    
window.mergeRules = (rule1, rule2) ->
    new_rule = {rules: {}, messages: {}, validate_cssclass: ""}
    new_rule.rules = $.extend({},rule1.rules, rule2.rules)
    new_rule.messages = $.extend({},rule1.messages, rule2.messages)
    v_c = null
    if rule2.validate_cssclass
        v_c = rule2.validate_cssclass
    else
        v_c = rule1.validate_cssclass
    new_rule.validate_cssclass = v_c
    new_rule
    
window.oTableText = 
    "sLengthMenu": "每页显示 _MENU_ 条记录",
    "sZeroRecords": "没有结果",
    "sInfo": "此页显示从_START_到 _END_条记录 (共有 _TOTAL_条记录)",
    "sInfoEmpty": "没有结果 ",
    "sInfoFiltered": "(从 _MAX_ 条记录中筛选)"
    "oPaginate": {sFirst: "首页", sPrevious: "向前", sNext: "向后", sLast: "末页"}
    "sInfoPostFix": ""
    sProcessing: "正在为您加载数据..."
    sSearch: "搜索"
    sUrl: ""
    
window.today = new Date()

window.getDateStr = ()->
    (window.today.getFullYear()) + "-" + (window.today.getMonth() + 1) + "-" + (window.today.getDate())
  

class window.WaitingView extends Marionette.ItemView
    template: "#waiting"

    
class window.TitleView extends Marionette.ItemView
    template: "#table_title_template"
    initialize: =>
        @listenTo @model, "change", @on_model_change
        @listenTo @, "all", @onThisAll
    onThisAll: (name) => log "ModelSearchView on this event: " + name
    on_model_change: =>
        log "TitleView on its model changed."
    
class window.NewModelForm extends Marionette.CompositeView
    template: "#new_model_form_template"
    initialize: =>
        @listenTo @model, "change", @on_model_change
        @listenTo @, "all", @onThisAll
    onThisAll: (name) => log "NewModelForm on this event: " + name
    on_model_change: =>
        log "NewModelForm on its model changed."
    onRender: =>
        @$(".datepicker").datepicker();
        @$(".datetimepicker").datetimepicker();
        @$("#ui-datepicker-div").hide()
    events: =>
        'click': (e) =>
            
        
class window.ModelSearchView extends Marionette.ItemView
    template: "#model_search_view"
    initialize: (options) =>
        @fnOrigServerData = options.fnOrigServerData
        @listenTo @model, "change", @on_model_change
        @listenTo @, "all", @onThisAll
    onThisAll: (name) => log "ModelSearchView on this event: " + name
    on_model_change: =>
        log "ModelSearchView on its model changed."
    events: =>
        'click #searchModelButton':  (e) =>
            e.preventDefault()
            form = $("#searchForm")
            @oTable.fnSettings().fnServerData = (sSource, aoData, fnCallback, oSettings) =>
                for item_content in $(".search_item_content", form)
                    c = $("[rel]", item_content)
                    if c.length > 1
                        for d, index in aoData
                            if d.name == "sSearch_" + $(c[0]).attr('rel')
                                aoData[index].value = $(c[0]).attr('cl_type') + '|' + $(c[0]).attr('value') + '|' + $(c[1]).attr('value')
                    else if c.length > 0
                        for d, index in aoData
                            if d.name == "sSearch_" + $(c[0]).attr('rel')
                                aoData[index].value = $(c[0]).attr('cl_type') + '|' + $(c[0]).attr('value')
                @fnOrigServerData(sSource, aoData, fnCallback, oSettings)
            @oTable.fnDraw() 
            
        'click #quick_search_btn':  (e) =>
            e.preventDefault()
            form = $(e.target.parentNode)
            @oTable.fnSettings().fnServerData = (sSource, aoData, fnCallback, oSettings) =>
                for item_content in $(".search_item_content", form)
                    c = $("[rel]", item_content)
                    if c.length > 1
                        for d, index in aoData
                            if d.name == "sSearch_" + $(c[0]).attr('rel')
                                aoData[index].value = $(c[0]).attr('cl_type') + '|' + $(c[0]).attr('value') + '|' + c[1].attr('value')
                    else if c.length > 0
                        for d, index in aoData
                            if d.name == "sSearch_" + $(c[0]).attr('rel')
                                aoData[index].value = $(c[0]).attr('cl_type') + '|' + $(c[0]).attr('value')
                @fnOrigServerData(sSource, aoData, fnCallback, oSettings)
            @oTable.fnDraw() 

        'click #searchCancelButton': (e) =>
            oSearchForm = @$("#searchForm")
            @$("#collapseOne").collapse('hide')
            $(oSearchForm)[0].reset();
        'submit #uploadFileForm': (e) =>
            formObj = $(e.target);
            formURL = formObj.attr("action");
            iframeId = 'unique' + (new Date().getTime());
            iframe = $('<iframe src="javascript:false;" name="'+iframeId+'" />');
            iframe.hide();
            formObj.attr('target',iframeId);
            iframe.appendTo('body');
            iframe.load( (e) =>
                data = $(e.target).contents().find('body').text()
                if data.indexOf("error") == -1
                    #alert("照片上传成功")
                    @$("img").attr('src', data)
                    @$(".forimage").attr('value', data)
                else
                    alert("照片上传失败, 服务器返回：\n" + data)
                )
        'click #newModelOKButton': (e) =>
            oAddNewRowForm = @$("#formAddNewRowModel")
            if !oAddNewRowForm.valid()
                return
            params = oAddNewRowForm.serialize();
            oTable = @oTable
            oSettings = oTable.fnSettings();
            iDisplayStart = oSettings._iDisplayStart
            @showProcessingIcon(oTable)
            $.ajax(
                url: "/" + @model.get("name") + "/add"
                data: params
                type: 'POST'
                dataType: 'text'
                success: (response) =>
                    @hideProcessingIcon(oTable)
                    $('#AddRecord').modal('hide')
                    $(oAddNewRowForm)[0].reset();
                    $(".error", $(oAddNewRowForm)).html("");
                    oSettings._iDisplayStart = iDisplayStart;
                    oSettings.oApi._fnCalculateEnd(oSettings);
                    @oTable.fnDraw()
                error: (response) =>
                    @hideProcessingIcon(oTable)    
                    alert(response.responseText)
                )
        'click #newModelCancelButton': (e) =>
            oAddNewRowForm = @$("#formAddNewRowModel")
            @$("#collapseTwo").collapse('hide')
            oAddNewRowForm.validate().resetForm()
            $(oAddNewRowForm)[0].reset();
            e.preventDefault()
        
        'change #formAddNewRowModel select': (e) =>
            value = e.target.value
            cur_name = $(e.target).attr("name")
            cur_field_name = $(e.target).attr("co_primary_field_in_cotable")
            if !cur_field_name
                return
            #cur_field_name = 'vehicle.plate_number'
            cur_index = $(e.target).attr("rel")
            target_names = $(e.target).attr("co_connected_fields_in_this")
            if !target_names
                return
            target_names = target_names.split(',')
            #target_names = ['driver_our.name']
            target_field_names = $(e.target).attr("co_connected_fields_in_cotable")
            if !target_field_names
                return
            target_field_names = target_field_names.split(',')
            #target_field_names = ['driver.name']
            model_name = $(e.target).attr("co_table")
            if !model_name
                return
            #model_name = 'insurance'
            cl_type = $(e.target).attr("cl_type")
            if !cl_type
                cl_type = "String"
            
            request = @buildRequest(cur_index, cur_field_name, value, cl_type)
            @showWaitingIcon(cur_index)
            $.ajax(
                url: "/" + model_name
                data: request
                type: 'POST'
                dataType: 'text'
                success: (response) =>
                    @hideWaitingIcon(cur_index)
                    resp = jQuery.parseJSON(response)
                    if resp.iTotalRecords == 1
                        index = 0
                        for target_name in target_names
                            field_name = target_field_names[index]
                            field_name = field_name.split('.')
                            selector = "[name=" + target_name + "]"
                            selector = selector.replace(".", "\\.")
                            if field_name.length = 2
                                respField = resp.aaData[0][field_name[0]][field_name[1]]
                            else if field_name.length = 1
                                respField = resp.aaData[0][field_name[0]]
                            else
                                return
                            $(selector).val(respField)
                error: (response) =>
                    alert(response)
                    @hideWaitingIcon(cur_index)
                )
    
    showWaitingIcon: (index) =>
        @$("#loader"+index).show()
    hideWaitingIcon: (index) =>
        @$("#loader"+index).hide()
    buildRequest: (cur_index, cur_name, value, cl_type) =>
        total = 30
        request = {
            sEcho:'1'
            iColumns:'22'
            sColumns:''
            iDisplayStart:'0'
            iDisplayLength:'10'
            mDataProp_0:''
            mDataProp_1:''
            mDataProp_2:''
            mDataProp_3:''
            mDataProp_4:''
            mDataProp_5:''
            mDataProp_6:''
            mDataProp_7:''
            mDataProp_8:''
            mDataProp_9:''
            mDataProp_10:''
            mDataProp_11:''
            mDataProp_12:''
            mDataProp_13:''
            mDataProp_14:''
            mDataProp_15:''
            mDataProp_16:''
            mDataProp_17:''
            mDataProp_18:''
            mDataProp_19:''
            mDataProp_20:''
            mDataProp_21:''
            sSearch:''
            bRegex:'false'
            sSearch_0:''
            bRegex_0:'false'
            bSearchable_0:'true'
            sSearch_1:''
            bRegex_1:'false'
            bSearchable_1:'true'
            sSearch_2:''
            bRegex_2:'false'
            bSearchable_2:'true'
            sSearch_3:''
            bRegex_3:'false'
            bSearchable_3:'true'
            sSearch_4:''
            bRegex_4:'false'
            bSearchable_4:'true'
            sSearch_5:''
            bRegex_5:'false'
            bSearchable_5:'true'
            sSearch_6:''
            bRegex_6:'false'
            bSearchable_6:'true'
            sSearch_7:''
            bRegex_7:'false'
            bSearchable_7:'true'
            sSearch_8:''
            bRegex_8:'false'
            bSearchable_8:'true'
            sSearch_9:''
            bRegex_9:'false'
            bSearchable_9:'true'
            sSearch_10:''
            bRegex_10:'false'
            bSearchable_10:'true'
            sSearch_11:''
            bRegex_11:'false'
            bSearchable_11:'true'
            sSearch_12:''
            bRegex_12:'false'
            bSearchable_12:'true'
            sSearch_13:''
            bRegex_13:'false'
            bSearchable_13:'true'
            sSearch_14:''
            bRegex_14:'false'
            bSearchable_14:'true'
            sSearch_15:''
            bRegex_15:'false'
            bSearchable_15:'true'
            sSearch_16:''
            bRegex_16:'false'
            bSearchable_16:'true'
            sSearch_17:''
            bRegex_17:'false'
            bSearchable_17:'true'
            sSearch_18:''
            bRegex_18:'false'
            bSearchable_18:'true'
            sSearch_19:''
            bRegex_19:'false'
            bSearchable_19:'true'
            sSearch_20:''
            bRegex_20:'false'
            bSearchable_20:'true'
            sSearch_21:''
            bRegex_21:'false'
            bSearchable_21:'true'
            iSortCol_0:'0'
            sSortDir_0:'desc'
            iSortingCols:'1'
            bSortable_0:'true'
            bSortable_1:'true'
            bSortable_2:'true'
            bSortable_3:'true'
            bSortable_4:'true'
            bSortable_5:'true'
            bSortable_6:'true'
            bSortable_7:'true'
            bSortable_8:'true'
            bSortable_9:'true'
            bSortable_10:'true'
            bSortable_11:'true'
            bSortable_12:'true'
            bSortable_13:'true'
            bSortable_14:'true'
            bSortable_15:'true'
            bSortable_16:'true'
            bSortable_17:'true'
            bSortable_18:'true'
            bSortable_19:'true'
            bSortable_20:'true'
            bSortable_21:'true'
            _:'1392123827440'
        }
        dataProp = "mDataProp_" + cur_index
        search = "sSearch_" + cur_index
        request[dataProp] = cur_name
        request[search] = cl_type + '|' + value
        request
    showProcessingIcon: (oTable) =>
        if oTable.fnSettings().oFeatures.bProcessing
            $(".dataTables_processing").css('visibility', 'visible');
    hideProcessingIcon: (oTable) =>
        if oTable.fnSettings().oFeatures.bProcessing
            $(".dataTables_processing").css('visibility', 'hidden') 
    setTable: (table) =>
        @oTable = table
    onRender: =>
        #@$(".datepicker").datepicker();
        #@$(".datetimepicker").datetimepicker();
        @$("#formAddNewRowModel").validate(@getNewRowFormValidationObject());
        @$("#ui-datepicker-div").hide()
    getNewRowFormValidationObject: =>
        result = {rules: {}, messages: {}}
        for colum in @model.get('aoColums')
            id = colum["mData"]
            if colum["validation_rules"]
                result.rules[id] = colum["validation_rules"].rules
            if colum["validation_rules"]
                result.messages[id] = colum["validation_rules"].messages
        result
    uploadfile: =>
        @$('#fileupload').fileupload(
            url: '/pic/upload',
            dataType: 'json',
            autoUpload: false,
            acceptFileTypes: /(\.|\/)(gif|jpe?g|png)$/i,
            maxFileSize: 5000000,
            previewMaxWidth: 100,
            previewMaxHeight: 100,
            previewCrop: true
        )

    
class SimpleTableSchema extends Backbone.Model
    url: '/mytable/getModel?s=table.creators.InsuranceTable'
    initialize: (options) =>
        @fetch()
        
class window.DetailView extends Marionette.ItemView
    template: "#detail_view_template"    
    events: =>
        'click tbody td': (e) =>
            oTable = @table      
            nTr = e.target.parentNode     
            aPos = oTable.fnGetPosition( e.target );
            if !aPos #in edit mode
                return
            if aPos[0] == null
                return
            if aPos[1] == null
                return
            oSettings = oTable.fnSettings()
            aData = oTable.fnGetData( nTr )
            aoColumn = oSettings.aoColumns[ aPos[1] ]
            foreign_table = aoColumn.foreign_table;
            foreign_field = aoColumn.foreign_field;
            if foreign_table.length == 0
                return
            field_title = aoColumn.sTitle
            field_type = aoColumn.type
            filed_index = aPos[1]
            #filed_name = aoColumn.mData
            tokens = aoColumn.mData.split('.')
            if tokens.length != 2
                return
            field_value = aData[tokens[0]][tokens[1]]
            if oTable.fnIsOpen(nTr)
                @detail_view.remove()
                oTable.fnClose(nTr)
            else             
                oTable.fnOpen( nTr, @fnFormatDetails(@table, foreign_table, foreign_field, field_title, field_type, field_value, filed_index), 'details' );
            
    initialize: (options) =>
        @field_name = options.field_name
        @field_value = options.field_value
        @table_name = options.table_name
        @field_index = options.field_index
        @field_type = options.field_type
        @listenTo @model, "change", @on_model_change
        @listenTo @, "all", @onThisAll
    onThisAll: (name) => log "DetailView on this event: " + name
    on_model_change: =>
        log "DetailView on its model changed."
        @render()
    fnFormatDetails: ( @table, table_name, field_name, field_title, field_type, field_value, filed_index ) =>
        smodel = new Backbone.Model
        smodel.url = "/mytable/getModel?s=table.creators." + table_name.substring(0, 1).toUpperCase() + table_name.substring(1, table_name.length) + "Table"
        smodel.fetch()
        smodel.set('table_id', (new Date()).valueOf())
        @detail_view = new DetailView(model: smodel, 'field_name': field_name, 'field_value': field_value, 'table_name' : table_name, 'field_index' : filed_index, 'field_type': field_type )
        html = @detail_view.$el
        sOut = html
        sOut    
    onRender: =>
        aoColums = @model.get('aoColums')
        table_id = "#detail_table_" +@model.get('table_id');
        aoColumDefs = @getAoColumDefs()
        @table = @$(table_id).dataTable 
            "bProcessing": true
            "bServerSide": true
            "sAjaxSource": "/" + @model.get("name")
            "sDom": 'r'
            "aoColumns": aoColums
            "oLanguage": window.oTableText
            "bSort": false
            "aoColumnDefs": aoColumDefs
            "fnRowCallback": ( nRow, aData, iDisplayIndex, iDisplayIndexFull ) =>
                for td in $('td', nRow)
                    atd = $(td)
                    if atd.text().indexOf("/pic/") == 0
                        imgTag = '<img src="' + atd.text() + '" />'; 
                        atd.html(imgTag);
                nRow;
            "fnServerParams": (aoData) =>
                name = ''
                for d, index in aoData
                    p = d.name.indexOf('mDataProp_')
                    if p != -1 and d.value==@field_name
                        index = d.name.substring(10, d.name.length)
                        name = 'sSearch_' + index
                    if d.name == name
                        aoData[index].value = @field_type + "|" + @field_value
    getAoColumDefs: =>
        defs = []
        index = 0
        for colum in @model.get('aoColums')
            if colum.foreign_table.length > 0
                def = { "sClass": "has_detail", "aTargets": [ index ] } 
                defs.push(def)
            index = index + 1
        defs
                
class window.ModelTableView extends Marionette.ItemView
    template: "#model_table_template"
    events: =>
        'click tbody td': (e) =>
            oTable = @table      
            nTr = e.target.parentNode     
            aPos = oTable.fnGetPosition( e.target );
            if !aPos #in edit mode
                return
            if aPos[0] == null
                return
            if aPos[1] == null
                return
            oSettings = oTable.fnSettings()
            aData = oTable.fnGetData( nTr )
            aoColumn = oSettings.aoColumns[ aPos[1] ]
            foreign_table = aoColumn.foreign_table;
            foreign_field = aoColumn.foreign_field;
            if foreign_table.length == 0
                return
            field_title = aoColumn.sTitle
            field_type = aoColumn.type
            filed_index = aPos[1]
            tokens = aoColumn.mData.split('.')
            if tokens.length != 2
                return
            field_value = aData[tokens[0]][tokens[1]]
            if oTable.fnIsOpen(nTr)
                @detail_view.remove()
                oTable.fnClose(nTr)
            else             
                oTable.fnOpen( nTr, @fnFormatDetails(@table, foreign_table, foreign_field, field_title, field_type, field_value, filed_index), 'details' );
            
    initialize: (options) =>
        #@form_region = options.form_region
        @btnAddNewModel = options.btnAddNewModel
        @btnDeleteNewModel = options.btnDeleteNewModel
        @listenTo @model, "change", @on_model_change
        @listenTo @, "all", @onThisAll
    onThisAll: (name) => log "ModelTableView on this event: " + name
    on_model_change: =>
        log "ModelTableView on its model changed."
    getNewRowFormValidationObject: =>
        result = {rules: {}, messages: {}}
        for colum in @model.get('aoColums')
            id = colum["mData"]
            if colum["validation_rules"]
                result.rules[id] = colum["validation_rules"].rules
            if colum["validation_rules"]
                result.messages[id] = colum["validation_rules"].messages
        result    
    fnFormatDetails: ( @table, table_name, field_name, field_title, field_type, field_value, filed_index ) =>
        smodel = new Backbone.Model
        smodel.url = "/mytable/getModel?s=table.creators." + table_name.substring(0, 1).toUpperCase() + table_name.substring(1, table_name.length) + "Table"
        smodel.fetch()
        smodel.set('table_id', (new Date()).valueOf())
        @detail_view = new DetailView(model: smodel, 'field_name': field_name, 'field_value': field_value, 'table_name' : table_name, 'field_index' : filed_index, 'field_type': field_type )
        html = @detail_view.$el
        sOut = html
        sOut
    getAoColumDefs: =>
        defs = []
        index = 0
        for colum in @model.get('aoColums')
            if colum.foreign_table.length > 0
                def = { "sClass": "has_detail", "aTargets": [ index ] } 
                defs.push(def)
            index = index + 1
        defs
    getEditableAoColumns: =>
        result = []
        for colum in @model.get('aoColums')
            id = colum.mData
            ret = null
            
            if colum.editable
                ret = {}
                
            if colum.editable and colum.validation_rules
                ret = {cssclass: "", oValidationOptions: {rules: {}, messages: {}}}
                if colum.validation_rules.validate_cssclass
                    ret["cssclass"] = colum.validation_rules.validate_cssclass
                if colum.validation_rules.rules
                    ret["oValidationOptions"]["rules"] = {value: colum.validation_rules.rules};
                if colum.validation_rules.messages
                    ret["oValidationOptions"]["messages"] = {value: colum.validation_rules.messages};
                $.extend(ret, colum.editable_settings)
            result.push ret
            
        result
    onClose: =>
        $("#formAddNewRowModel").remove()
    onRender: =>
        newFormRules = @getNewRowFormValidationObject()
        editableRules = @getEditableAoColumns()
        aoColums = @model.get('aoColums')
        aoColumDefs = @getAoColumDefs()
        model_name = @model.get("name")
        @table = @$("#table_model").dataTable 
            "bProcessing": true
            "bServerSide": true
            "sAjaxSource": "/" + model_name
            "sDom": '<"#table_top"TC><"#table_body"tr><"#table_bottom"ip>'
            "aoColumns": aoColums
            "oLanguage": window.oTableText
            "aaSorting": [[ 0, "desc" ]]
            "oColVis": 
                "buttonText": "定制显示的列"
            #"fnDrawCallback": (oSetting) =>
            #    @makeEditable(oSetting)  //cause two time click
            "oTableTools":
                "sSwfPath": "/assets/swf/copy_csv_xls_pdf.swf"
            "aoColumnDefs": aoColumDefs
            "fnRowCallback": ( nRow, aData, iDisplayIndex, iDisplayIndexFull ) =>
                for td in $('td', nRow)
                    atd = $(td)
                    if atd.text().indexOf("/pic/") == 0
                        imgTag = '<img src="' + atd.text() + '" />'; 
                        atd.html(imgTag);
                nRow;
        mysearch = new ModelSearchView(model: @model, fnOrigServerData: @table.fnSettings().fnServerData)
        mysearch.render()
        mysearch.setTable @table
        
        @$(".DTTT_button_copy").hide()
        @$(".DTTT_button_csv").removeClass("DTTT_button").addClass("btn")
        @$(".DTTT_button_csv").text("导出Excel")
        @$(".DTTT_button_xls").hide()
        @$(".DTTT_button_pdf").hide()
        @$(".DTTT_button_print").hide()
        @$(".ColVis_MasterButton").addClass("btn")
  
        @$("#table_top").append(mysearch.el)
        @makeEditable(@$("#btnDeleteModel"))
        @$("#ui-datepicker-div").hide()
    makeEditable: (btnDelete) =>
        newFormRules = @getNewRowFormValidationObject()
        editableRules = @getEditableAoColumns()
        aoColums = @model.get('aoColums')
        @table.makeEditable
            sUpdateURL: "/" + @model.get("name") + "/update"
            sAddURL: "/" + @model.get("name") + "/add"
            sDeleteURL: "/" + @model.get("name") + "/delete"
            #sDeleteRowButtonId: "btnDeleteModel"
            #sAddNewRowButtonId: "btnAddNewModel"
            #sAddNewRowFormId: "formAddNewRowModel"
            #sAddNewRowCancelButtonId: "newModelCancelButton"
            #sAddNewRowOkButtonId: "newModelOKButton"
            #oAddNewRowFormOptions: 
            #    width: @model.get("newFormWidth")
            #oAddNewRowOkButtonOptions:
            #    label: "提交"
            #oAddNewRowCancelButtonOptions: 
            #    label: "取消"
            oEditableSettings:
                placeholder: ""
            #oAddNewRowFormValidation: newFormRules   
            aoColumns: editableRules
            #form_region: @form_region
            #btnAddNewModel: @btnAddNewModel
            btnDeleteNewModel: btnDelete
        #@$(".datepicker").datepicker();
        #@$(".datetimepicker").datetimepicker();
        @$("#ui-datepicker-div").hide()
            
class window.ModelMainLayout extends Marionette.Layout
    template: "#model_main_layout"
    initialize: =>
        if (@model)
            @listenTo @model, "change", @on_model_change
        @listenTo @, "all", @onThisAll
        @listenTo @, "dom:refresh", @onDomRefresh
    onThisAll: (name) => log "ModelMainLayout on this event: " + name
    on_model_change: =>
        log "ModelMainLayout on its model changed. ReRender..."
        @render()
    onRender: =>  
        if (@model.has('aoColums'))
            @region_title.show new TitleView(model: @model)
          
            #@region_new.show new NewModelForm(model: @model)
            
            #mysearch = new ModelSearchView(model: @model)
            #@region_search.show mysearch
            
            mytable = new ModelTableView(model: @model, btnAddNewModel: $("#btnAddNewModel", $(@el)), btnDeleteNewModel:$("#btnDeleteModel", $(@el)))
             
            @region_table.show mytable
            

            
        @$(".datepicker").datepicker();
        @$(".datetimepicker").datetimepicker();
        $("#ui-datepicker-div").hide()

    regions:
        region_title: "#table_title"
        region_new: "#new_model_form_container"
        region_search: "#model_search_view_container"
        region_table: "#model_table"